<template>
  <div>
    <PageTemplate>
      <div slot="content">
        <PageEditCollapse :is-search="false" :default-collapse="true">
          <div slot="title" class="page-edit-colllapse-title">
            <div style="width: 200px;">{{$t('cm.baseinfo')}}</div>
          </div>
          <div>
            <el-form
              :model="milestone"
              label-position="right"
              label-width="150px"
              class="page-edit-colllapse-form"
              :rules="rules"
              ref="milestone"
            >
              <el-row>
                <el-col :span="12">
                  <el-form-item :label="'机组'" prop="wbs">
                    <el-input v-model="milestone.wbs"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item :label="'FCD'" prop="jihuazhi">
                    <el-input v-model="milestone.jihuazhi"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item :label="'SDA调试开始'" prop="yindezhi">
                    <el-input v-model="milestone.yindezhi"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item :label="'泵站进水'" prop="yucezhi">
                    <el-input v-model="milestone.yucezhi"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item :label="'500KV可用'" prop="shijizhi">
                    <el-input v-model="milestone.shijizhi"></el-input>
                  </el-form-item>
                </el-col>

                <el-col :span="12">
                  <el-form-item :label="'冷试'" prop="spi">
                    <el-input v-model="milestone.spi"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item :label="'热试'" prop="reshi">
                    <el-input v-model="milestone.reshi"></el-input>
                  </el-form-item>
                </el-col>

                <el-col :span="12">
                  <el-form-item :label="'装料'" prop="zliao">
                    <el-input v-model="milestone.zliao"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item :label="'首次核临界'" prop="schlj">
                    <el-input v-model="milestone.schlj"></el-input>
                  </el-form-item>
                </el-col>

                <el-col :span="12">
                  <el-form-item :label="'并网'" prop="bingwang">
                    <el-input v-model="milestone.bingwang"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item :label="'运商'" prop="yunshang">
                    <el-input v-model="milestone.yunshang"></el-input>
                  </el-form-item>
                </el-col>

                <el-col :span="12">
                  <el-form-item :label="'排序数字'" prop="xunhao">
                    <el-input v-model="milestone.xunhao"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
          </div>
        </PageEditCollapse>
        <el-row class="row-empty-10"></el-row>
        <el-row>
          <el-button type="primary" @click="submitForm('milestone')" :loading="submiting" class="loading-submiting">
            {{$t('cm.commit')}}
          </el-button>
          <el-button type="primary" @click="toList">
            {{$t('cm.return')}}
          </el-button>
        </el-row>
      </div>
    </PageTemplate>
  </div>
</template>

<script>
import { ALERT } from '@/utils/responseHandle'
import * as Constant from '@/utils/constant'
import PageTemplate from '@/components/common/PageTemplate'
import PageEditCollapse from '@/components/common/PageEditCollapse'
import HasBtn from '@/mixins/HasBtn'
import { mapState } from 'vuex'
import {COMMON} from '@/utils/commonUtil'
import sys_manage from '@/api/sys_manage'
import Submiting from '@/mixins/Submiting'
export default {
  components: {
    PageTemplate, PageEditCollapse
  },
  mixins: [Submiting],
  data () {
    return {
      weights: [Constant.TIP_WEIGHT_1,Constant.TIP_WEIGHT_9],
      milestone: {
        id: null,
        wbs: null,
        jihuazhi: null,
        yindezhi: null,
        yucezhi: null,
        shijizhi: null,
        spi: null,
        reshi: null,
        zliao: null,
        schlj: null,
        bingwang: null,
        yunshang: null,
        xunhao: null
      },
      rules: {
        wbs: [
          { required: true, message: '必填项', trigger: 'blur' }
        ],
        jihuazhi: [
          { required: true, message: '必填项', trigger: 'change' }
        ],
        yindezhi: [
          { required: true, message: '必选项', trigger: 'change' }
        ],
        xunhao: [
          { required: true, message: '必选项', trigger: 'change' }
        ]
      }
    }
  },
  created () {
    if (this.$router.history.current.params.id !== Constant.NEW_PARAMS) {
      this.sysMilestoneGet(this.$router.history.current.params.id)
    }
  },
  methods: {
    sysMilestoneGet (id) {
      sys_manage.sysMilestoneGet({id}, result => {
        if (result.code === Constant.RT_SUCCESS) {
          this.milestone = result.data
        } else {
          // _this.$t('cm.tips')
          ALERT.error(result.msg)
        }
      })
    },
    submitForm (formName) {
      this.openSubmiting()
      this.$refs[formName].validate((valid, error) => {
        if (valid) {
          sys_manage.sysMilestoneSave(this.milestone, result => {
            if (result.code === Constant.RT_SUCCESS) {
              ALERT.success(result.msg)
              this.toList()
            } else {
              // _this.$t('cm.tips')
              ALERT.error(result.msg)
            }
            this.closeSubmiting()
          })
        } else {
          this.closeSubmiting()
          return false
        }
      })
    },
    toList () {
      COMMON.routerTo(Constant.ROUTE_SYS_MILESTONE.index, this.$router)
    }
  },
  mounted () {
  },
  computed: {
    ...mapState({
      isValids: state => state.dict.isValids
    })
  }
}
</script>

<style lang="scss">
</style>
